
def joystick_port_2:byte		@ 56320

def joystick_up:byte
def joystick_down:byte
def joystick_left:byte
def joystick_right:byte
def joystick_fire:byte

def joystick_last:byte


sub process_joystick() {
	if(joystick_last <> joystick_port_2) {
		// Only enter if joystick has changed, this gives the possibility to "mark joystick positions" as already read
		joystick_last = joystick_port_2

		def tmp:byte
		def tmp2:byte

		tmp = joystick_port_2
		tmp2 = tmp & 16
		if(tmp2 = 0) {
			joystick_fire = 1
		}
		else {
			joystick_fire = 0
		}

		tmp2 = tmp & 8
		if(tmp2 = 0) {
			joystick_right = 1
		}
		else {
			joystick_right = 0
		}

		tmp2 = tmp & 4
		if(tmp2 = 0) {
			joystick_left = 1
		}
		else {
			joystick_left = 0
		}

		tmp2 = tmp & 2
		if(tmp2 = 0) {
			joystick_down = 1
		}
		else {
			joystick_down = 0
		}

		tmp2 = tmp & 1
		if(tmp2 = 0) {
			joystick_up = 1
		}
		else {
			joystick_up = 0
		}
	}
}


 
